home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / autoit / autoit-v3.2.0.1-setup.exe / Examples / Helpfile / ObjGet.au3 < prev    next >
Encoding:
Text File  |  2006-06-17  |  1.8 KB  |  54 lines

  1. ; Example getting an Object using it's class name
  2. ;
  3. ; Excel must be activated for this example to be successfull
  4.  
  5. $oExcel = ObjGet("","Excel.Application")    ; Get an existing Excel Object
  6.  
  7. if @error then 
  8.   Msgbox (0,"ExcelTest","Error Getting an active Excel Object. Error code: " & hex(@error,8))
  9.   exit
  10. endif
  11.  
  12. $oExcel.Visible = 1        ; Let the guy show himself
  13. $oExcel.workbooks.add        ; Add a new workbook
  14. exit
  15.  
  16.  
  17.  
  18. ; Example getting an Object using a file name
  19. ;
  20. ; An Excel file with filename Worksheet.xls must be created in the root directory
  21. ; of the C:\ drive in order for this example to work.
  22.  
  23. $FileName="C:\Worksheet.xls"
  24.  
  25. if not FileExists($FileName) then
  26.   Msgbox (0,"Excel File Test","Can't run this test, because you didn't create the Excel file "& $FileName)
  27.   Exit
  28. endif
  29.  
  30. $oExcelDoc = ObjGet($FileName)    ; Get an Excel Object from an existing filename
  31.  
  32. if IsObj($oExcelDoc) then
  33.  
  34.   ; Tip: Uncomment these lines to make Excel visible (credit: DaleHohm)
  35.   ; $oExcelDoc.Windows(1).Visible = 1; Set the first worksheet in the workbook visible
  36.   ; $oExcelDoc.Application.Visible = 1; Set the application visible (without this Excel will exit)
  37.  
  38.   $String = ""        ; String for displaying purposes
  39.  
  40.   ; Some document properties do not return a value, we will ignore those.
  41.   $OEvent=ObjEvent("AutoIt.Error","nothing"); Equal to VBscript's On Error Resume Next
  42.   
  43.   For $Property In $oExcelDoc.BuiltinDocumentProperties
  44.      $String = $String &  $Property.Name & ":" & $Property.Value & @CRLF
  45.   Next
  46.  
  47.   Msgbox(0,"Excel File Test","The document properties of " & $FileName & " are:" & @CRLF & @CRLF & $String)
  48.  
  49.   $oExcelDoc.Close        ; Close the Excel document
  50.  
  51. else
  52.   Msgbox (0,"Excel File Test","Error: Could not open "& $FileName & " as an Excel Object.")
  53. endif
  54.